import hashlib
import json
import random

import requests


#get请求去重

# resquest_urls = set()
#
#
# urls = [f"https://httpbin.org/get?value={random.randint(1,10)}"for i in range(10)]
#
# for url in urls:
#     if url not in resquest_urls:
#         resquest_urls.add(url)
#         res = requests.get(url)
#         print(res.json())
#     else:
#         print("重复请求")



#post请求去重

resquest_urls = set()

url = "https://httpbin.org/post"

datas = [{"value": random.randint(1,10)} for i in range(10)]

for data in datas:
    data_hash = hashlib.md5(json.dumps(data).encode()).hexdigest()
    if data_hash not in resquest_urls:
        resquest_urls.add(data_hash)
        res = requests.post(url, data= data)
        print(res.json())
    else:
        print("重复请求")
